package com.sugar.service.oa.hr;

import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sugar.base.query.BaseQuery;
import com.sugar.base.query.PageModel;
import com.sugar.domain.oa.hr.Organization;
import com.sugar.persistence.oa.hr.IOrganization;

@Service
public class OrganizationServiceBean implements IOrganizationService{
	
	@Resource
	private IOrganization orgdao ;

	@Override
	public void deleteOrgService(String id) throws RuntimeException {
		
		this.orgdao.deleteOrgDao(this.loadOrgByIdService(id)) ;
	}

	@Override
	public List<Organization> findOrgService(Object[] param)
			throws RuntimeException {
		
		String queryString = "select o from Organization o" ;
		
		return this.orgdao.findOrgDao(queryString, null, param, null) ;
		
	}

	@Override
	public PageModel<Organization> getScorllOrgService(Object[] param,
			int firstPage, int pageSize) throws RuntimeException {
		String queryString = "select o from Organization o" ;
		
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>() ;
		orderby.put("o.establishTime", BaseQuery.ASC) ;
		return this.orgdao.getScorllOrgDao(queryString, null, param, firstPage, pageSize, null);
	}

	@Override
	public Organization loadOrgByIdService(String id) throws RuntimeException {
		
		return this.orgdao.loadOrgByIdDao(id) ;
	}

	@Override
	public void saveOrgService(Organization org) throws RuntimeException {
		//org.setOrgCode("SG" + RandomUtil.getRandomNum(7)) ;
		this.orgdao.saveOrgDao(org) ;
	}

	@Override
	public void updateOrgService(Organization org) throws RuntimeException {
		this.orgdao.updateOrgDao(org) ;
	}

	@Override
	public void deleteSelectOrgService(Object[] ids) throws RuntimeException {
		this.orgdao.deleteSelectOrgDao(ids) ;
	}

}
